home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume5 / ml < prev    next >
Encoding:
Internet Message Format  |  1989-02-03  |  5.6 KB

  1. Path: xanth!nic.MR.NET!hal!ncoast!allbery
  2. From: ccea3@rivm.UUCP (Adri Verhoef)
  3. Newsgroups: comp.sources.misc
  4. Subject: v05i018: ml: A catagorial mail divider (sorts by Subject into separate files)
  5. Keywords: mailx sysV
  6. Message-ID: <1060@rivm05.UUCP>
  7. Date: 28 Oct 88 03:02:55 GMT
  8. Sender: allbery@ncoast.UUCP
  9. Reply-To: ccea3@rivm.UUCP (Adri Verhoef)
  10. Organization: RIVM, Bilthoven, The Netherlands
  11. Lines: 204
  12. Approved: allbery@ncoast.UUCP
  13.  
  14. Posting-number: Volume 5, Issue 18
  15. Submitted-by: "Adri Verhoef" <ccea3@rivm.UUCP>
  16. Archive-name: ml
  17.  
  18. Daily I receive some 65 to about 100 mail messages as they are contributed
  19. from some 30 machines by loginnames as
  20.     bin, news, lp, *uucp*
  21. who have their messages forwarded to a central/private single $MAIL file.
  22. To put these messages into categories I order them by Subject and put them
  23. into separate files.  Then I pg(1) these files to look at their contents.
  24.  
  25. - It works as follows:
  26. I call the mailer to show me the messages with possible Subjects; then I
  27. order by Subject and awk(1) them into categories; then I s(ave) the
  28. messages per Subject into files with a useful name; then per file I
  29. preprocess (e.g. sed(1)) the file and pg(1) the output.
  30.  
  31. NOTES:
  32. - Only New or Unread articles are s(ave)d.
  33. - After reading, the files get processed by 'rm'; you may want to change
  34.   this into a mv(1) command [if your own 'rm' doesn't do that already].
  35. - You may add or delete Subjects as you prefer personally.  If you do so,
  36.   you may have to add or delete a Subject in two (or three) places in 'ml'.
  37. - The default directory for the saved article files is named "Mail".
  38.  
  39. Here it is, folks, enjoy:
  40.  
  41. #! /bin/sh
  42. # This is a shell archive.  Remove anything before this line, then unpack
  43. # it by saving it into a file and typing "sh file".  To overwrite existing
  44. # files, type "sh file -c".  You can also feed this as standard input via
  45. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  46. # will see the following message at the end:
  47. #        "End of shell archive."
  48. # Contents:  ml
  49. # Wrapped by a3@rivm on Thu Sep 29 18:26:06 1988
  50. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  51. if test -f ml -a "${1}" != "-c" ; then 
  52.   echo shar: Will not over-write existing file \"ml\"
  53. else
  54. echo shar: Extracting \"ml\" \(3114 characters\)
  55. sed "s/^X//" >ml <<'END_OF_ml'
  56. X#ident    "@(#)ml.sh    1.1.3    (a3)    8 aug 1988"
  57. X# Save certain articles, currently in spooled mailbox, into several files, and
  58. X# read those files, and clean them up.  Then proceed reading the rest.
  59. X
  60. X[ -d Mail -a -w Mail ] || { echo "Directory 'Mail' not available."; exit 1; }
  61. Xcd Mail || exit 2
  62. X
  63. Xart_id=1
  64. Xsender=2
  65. X#dayOwk=3
  66. X#monOyr=4
  67. X#dayOmo=5
  68. X#timOdy=6
  69. Xartsiz=7
  70. Xsubj_1=8
  71. Xsubj_2=9
  72. Xsubj_3=10
  73. Xsubj_4=11
  74. X
  75. Xmailx -H |
  76. X sed -n 's/^ [NU]//p' |    #new or unread
  77. X  awk '
  78. X   NF=='$artsiz' {
  79. X    if ($'$sender'~/lp$/) f="lp";
  80. X    if ($'$sender'~/root$/) f="root";
  81. X    if ($'$sender'~/uucp$/) f="uucp";
  82. X   }
  83. X   NF=='$subj_1' {
  84. X    if ($(NF)=="/usr/spool/uucp/.Corrupt") f="Corrupt";
  85. X    if ($(NF)=="cleanup") f=$(NF);
  86. X    if ($(NF)=="cores") f=$(NF);
  87. X    if ($(NF)=="transfer-statistics") f="xfer";
  88. X    if ($(NF)=="uu-status") f=$(NF);
  89. X   }
  90. X   $'$subj_1'=="Newsgroup" {
  91. X    f=$'$subj_1';
  92. X   }
  93. X   NF=='$subj_2' {
  94. X    if ($(NF-1)=="UucpLog") f=$(NF-1);
  95. X    if ($(NF-1)=="trimlib") f=$(NF-1);
  96. X    if ($(NF-1)=="uucp") {
  97. X        if ($(NF)=="Admin") f=$(NF);
  98. X        if ($(NF)=="DENIED") f=$(NF);
  99. X        if ($(NF)=="requests") f=$(NF);
  100. X    }
  101. X   }
  102. X   NF=='$subj_3' {
  103. X    if ($(NF-2)=="Diskgebruik" && $(NF-1)=="op") f=$(NF-2);
  104. X    if ($(NF-2)=="Warning" && $(NF-1)=="From") f=$(NF-2);
  105. X    if ($(NF-2)=="sendsys" && $(NF-1)=="control") f=$(NF-2);
  106. X    if ($(NF-2)=="uucleanup" && $(NF-1)=="ran;") f=$(NF-2);
  107. X   }
  108. X   NF=='$subj_4' {
  109. X    if ($(NF-3)=="Problems" && $(NF)=="active") f=$(NF-3);
  110. X    if ($(NF-3)=="response" && $(NF)=="sendsys") f=$(NF-3);
  111. X   }
  112. X   {
  113. X    if (f=="") next;
  114. X    file[f]=file[f]" "$'$art_id';
  115. X    f="";
  116. X    ct++;
  117. X   }
  118. X   END {
  119. X    if (ct==0) exit(1);
  120. X    for (f in file) {
  121. X        max=480;
  122. X        if (length(file[f]) > max) {
  123. X            n=max;
  124. X            while (substr(file[f],n,1)!=" ") n--;
  125. X            printf("s%s %s\n",substr(file[f],1,n),f);
  126. X        }
  127. X        else printf("s%s %s\n",file[f],f);
  128. X    }
  129. X    for (f in file) if (f=="xfer") { print "|",file[f],"\"pg\""; break; }
  130. X   }
  131. X  ' | { [ $? = 0 ] && mailx; }
  132. X
  133. Xfor f in "lp" "root" "uucp" \
  134. X    "Corrupt" "Newsgroup" "cleanup" "cores" "uu-status" \
  135. X    "UucpLog" "trimlib" "Admin" "DENIED" "requests" \
  136. X    "sendsys" "uucleanup" "Diskgebruik" "Warning" \
  137. X    "Problems" "response" \
  138. X    # "xfer"    # Always as last one.  But already taken care of.
  139. Xdo
  140. X [ -f "$f" ] || continue
  141. X echo $f
  142. X case $f in
  143. X  "Diskgebruik") mailx -f "$f";;
  144. X  "UucpLog") pg "$f";;
  145. X  "uu-status")
  146. X    sed '    
  147. X        /^From/ {
  148. X            N
  149. X            D
  150. X        }
  151. X        /^>From/ {
  152. X            N
  153. X            /^>From.*\n>From/ {
  154. X                D
  155. X            }
  156. X        }
  157. X        s/\nSubject: .*//
  158. X        /^Status: /d
  159. X        /^$/d
  160. X    ' "$f" | pg;;
  161. X  "Admin"|"Corrupt"|"DENIED"|"Problems"|"cleanup"|"lp"|"requests"|"root"|"uucp")
  162. X    sed '    
  163. X        /^From/ {
  164. X            N
  165. X            /^From.*\n>From/ {
  166. X                D
  167. X            }
  168. X        }
  169. X        /^>From/ {
  170. X            N
  171. X            /^>From.*\n>From/ {
  172. X                D
  173. X            }
  174. X        }
  175. X        s/\nSubject: .*//
  176. X        s/\nStatus: .*//
  177. X        /^Status: /d
  178. X        /^$/d
  179. X    ' "$f" | pg;;
  180. X#  "Corrupt"|"lp"|"root"|"uucp")
  181. X#    sed '    
  182. X#        /^Status: /d
  183. X#        /^$/d
  184. X#    ' "$f" | pg;;
  185. X  "trimlib")
  186. X    sed '    
  187. X        /^>From /d
  188. X        /^To: /d
  189. X        /^Status: /d
  190. X    ' "$f" | pg;;
  191. X  "uucleanup") sed -n '/.Xqtdir/p' "$f" | pg;;
  192. X  # "xfer") ;;# Already taken care of.
  193. X  *)
  194. X    sed '
  195. X        /^>From /d
  196. X        /^Status: /d
  197. X        /^$/d
  198. X    ' "$f" | pg
  199. X    ;;
  200. X esac
  201. X [ $? = 0 ] && [ "xfer" != "$f" ] && rm "$f"
  202. Xdone
  203. X
  204. Xecho "Read mail ? [YN]\c"
  205. Xread x
  206. Xcase $x in
  207. X [Yy]) exec mailx;;
  208. Xesac
  209. END_OF_ml
  210. if test 3114 -ne `wc -c <ml`; then
  211.     echo shar: \"ml\" unpacked with wrong size!
  212. fi
  213. chmod +x ml
  214. # end of overwriting check
  215. fi
  216. echo shar: End of shell archive.
  217. exit 0
  218.